//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  Board_iPhone_Register1.m
//  DingDing
//
//  Created by LHL on 14/11/22.
//  Copyright (c) 2014年 com.gordon. All rights reserved.
//

#import "Board_iPhone_Register1.h"
#import "Board_iPhone_Register2.h"
#pragma mark -

@interface Board_iPhone_Register1()
{
	//<#@private var#>
}
@end

@implementation Board_iPhone_Register1

SUPPORT_AUTOMATIC_LAYOUT( YES )
SUPPORT_RESOURCE_LOADING( YES )
DEF_MODEL(sendMessageCode, isendMessageCode)
DEF_OUTLET(BeeUITextField, phonetext)
- (void)load
{
    self.isendMessageCode = [sendMessageCode modelWithObserver:self];
}

- (void)unload
{
}
-(sendMessageCode *)iiphoneCodeVerify{
    return self.isendMessageCode;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}


ON_SIGNAL3(sendMessageCode, RELOADED, SIGNAL){
    [self dismissTips];
    if ([[self iiphoneCodeVerify].code isEqualToString:@"200"]) {
        Board_iPhone_Register2 *res = [[Board_iPhone_Register2 alloc]init];
        res.numHint.text = [NSString stringWithFormat:@"验证码已发送至：%@",self.phonetext.text];
        res.phoneNum = self.phonetext.text;
        [self.navigationController pushViewController:res animated:YES];
    }else{
        if ([[self iiphoneCodeVerify].code isEqualToString:@""]|| [self iiphoneCodeVerify].code ==nil) {
            [self presentMessageTips:@"网络链接错误"];
        }else{
            [self presentMessageTips:[self isendMessageCode].message];
        }
    }
    
}

ON_SIGNAL3(sendMessageCode, RELOADING, SIGNAL){
    [self presentLoadingTips:@"加载中"];
}

ON_SIGNAL3(sendMessageCode, FAILED, SIGNAL){
    
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{

    self.navigationBarShown = YES;
    if (IOS7_OR_EARLIER) {        CGRect rect = self.mainView.frame;
        rect.origin.y = 64;
        self.mainView.frame = rect;
    }
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    self.title = @"注册";
    [self.view bringSubviewToFront:self.phonetext];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 40, 40);
    [button addTarget:self action:@selector(nextView) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"下一步" forState:0];
    [button.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [button setTitleColor:[UIColor whiteColor] forState:0];
    UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [v addSubview:button];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationBarLeft = [UIImage imageNamed:@"back.png"];

}

-(void)rightFunc{
    
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)nextView{
    if ([self.phonetext.text isTelephone]) {
        [self iiphoneCodeVerify].phone = self.phonetext.text;
        [[self iiphoneCodeVerify]firstPage];
    }else{
        [self presentMessageTips:@"请输入正确的手机号码"];
    }
//    Board_iPhone_Register2 *res = [[Board_iPhone_Register2 alloc]init];
//    res.numHint.text = [NSString stringWithFormat:@"验证码已发送至：%@",self.phoneNum.text];
//    res.phoneNum = self.phoneNum.text;
//    [self.navigationController pushViewController:res animated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
    
}

@end
